function addWaterMarker(str: string, parentNode: { appendChild: (arg0: HTMLCanvasElement) => void }, font: string, textColor: string) {
  // 水印文字，父元素，字体，文字颜色
  const can = document.createElement('canvas')
  parentNode.appendChild(can)
  can.width = 200
  can.height = 150
  can.style.display = 'none'
  const cans:any = can.getContext('2d')
  cans.rotate((-20 * Math.PI) / 180)
  cans.font = font || '16px Microsoft JhengHei'
  cans.fillStyle = textColor || 'rgba(180, 180, 180, 0.3)'
  cans.textAlign = 'left'
  cans.textBaseline = 'middle'
  cans.fillText(str, can.width / 10, can.height / 2)
  // parentNode.style.backgroundImage = 'url(' + can.toDataURL('image/png') + ')'

  const div = document.createElement('div')
  div.id = 'watermark'
  div.style.pointerEvents = 'none'
  div.style.top = '0px'
  div.style.left = '0px'
  div.style.position = 'fixed'
  div.style.zIndex = '100000'
  div.style.width = document.documentElement.clientWidth + 'px'
  div.style.height = document.documentElement.clientHeight + 'px'
  div.style.background =
    'url(' + can.toDataURL('image/png') + ') left top repeat'
  document.body.appendChild(div)
}

export default {
  mounted: function(el: { appendChild: (arg0: HTMLCanvasElement) => void }, binding: { value: { text: string; font: string; textColor: string } }) {
    addWaterMarker(binding.value.text, el, binding.value.font, binding.value.textColor)
  }
}

